package com.ruoyi.web.controller.fx;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.fx.FxTag;
import com.ruoyi.system.service.fx.IFxTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 标签管理Controller
 *
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/fx/tag")
public class FxTagController extends BaseController {
    @Autowired
    private IFxTagService fxTagService;

    /**
     * 查询标签管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FxTag fxTag) {
        startPage();
        List<FxTag> list = fxTagService.selectFxTagList(fxTag);
        return getDataTable(list);
    }

    /**
     * 导出标签管理列表
     */
    @Log(title = "标签管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FxTag fxTag) {
        List<FxTag> list = fxTagService.selectFxTagList(fxTag);
        ExcelUtil<FxTag> util = new ExcelUtil<FxTag>(FxTag.class);
        util.exportExcel(response, list, "标签管理数据");
    }

    /**
     * 获取标签管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fxTagService.selectFxTagById(id));
    }

    /**
     * 新增标签管理
     */
    @Log(title = "标签管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FxTag fxTag) {
        return toAjax(fxTagService.insertFxTag(fxTag));
    }

    /**
     * 修改标签管理
     */
    @Log(title = "标签管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FxTag fxTag) {
        return toAjax(fxTagService.updateFxTag(fxTag));
    }

    /**
     * 删除标签管理
     */
    @Log(title = "标签管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fxTagService.deleteFxTagByIds(ids));
    }
}
